package com.zr.eim.service.impl;

import java.util.List;
import com.zr.eim.domain.EimAnalysisScreen;
import com.zr.eim.domain.EimDataPerson;
import com.zr.eim.mapper.EimDataPersonMapper;
import org.springframework.stereotype.Service;
import com.zr.eim.mapper.EimOuterCitizenMapper;
import com.zr.eim.domain.EimOuterCitizen;
import com.zr.eim.service.IEimOuterCitizenService;

import javax.annotation.Resource;

/**
 * 外部输入人员Service业务层处理
 * 
 * @author haomingxue
 * @date 2022-10-25
 */
@Service
public class EimOuterCitizenServiceImpl implements IEimOuterCitizenService 
{
    @Resource
    private EimOuterCitizenMapper eimOuterCitizenMapper;

    @Resource
    private EimDataPersonMapper personMapper;

    /**
     * 查询外部输入人员
     * 
     * @param pid 外部输入人员主键
     * @return 外部输入人员
     */
    @Override
    public EimOuterCitizen selectEimOuterCitizenByPid(Long pid)
    {
        return eimOuterCitizenMapper.selectEimOuterCitizenByPid(pid);
    }

    /**
     * 查询外部输入人员列表
     * 
     * @param eimOuterCitizen 外部输入人员
     * @return 外部输入人员
     */
    @Override
    public List<EimOuterCitizen> selectEimOuterCitizenList(EimOuterCitizen eimOuterCitizen)
    {
        return eimOuterCitizenMapper.selectEimOuterCitizenList(eimOuterCitizen);
    }

    /**
     * 新增外部输入人员
     * 
     * @param eimOuterCitizen 外部输入人员
     * @return 结果
     */
    @Override
    public int insertEimOuterCitizen(EimOuterCitizen eimOuterCitizen)
    {
        return eimOuterCitizenMapper.insertEimOuterCitizen(eimOuterCitizen);
    }

    /**
     * 修改外部输入人员
     * 
     * @param eimOuterCitizen 外部输入人员
     * @return 结果
     */
    @Override
    public int updateEimOuterCitizen(EimOuterCitizen eimOuterCitizen)
    {
        return eimOuterCitizenMapper.updateEimOuterCitizen(eimOuterCitizen);
    }

    /**
     * 批量删除外部输入人员
     * 
     * @param pids 需要删除的外部输入人员主键
     * @return 结果
     */
    @Override
    public int deleteEimOuterCitizenByPids(Long[] pids)
    {
        return eimOuterCitizenMapper.deleteEimOuterCitizenByPids(pids);
    }

    /**
     * 删除外部输入人员信息
     * 
     * @param pid 外部输入人员主键
     * @return 结果
     */
    @Override
    public int deleteEimOuterCitizenByPid(Long pid)
    {
        return eimOuterCitizenMapper.deleteEimOuterCitizenByPid(pid);
    }


    /**
     * 查询七日内入境人数及境外输入病例数
     * 需求模块：数据大屏
     */
    @Override
    public List<EimAnalysisScreen> getOuterCitizen(){
        return eimOuterCitizenMapper.getOuterCitizen();
    }

    @Override
    public List<EimAnalysisScreen> getOuterDiagnostic(){
        return eimOuterCitizenMapper.getOuterDiagnostic();
    }

    /**
     * 外部输入人员管理模块定时任务
     */
    public void outerCitizenToDataPerson() {
        List<EimOuterCitizen> list = eimOuterCitizenMapper.selectEimOuterCitizenList(new EimOuterCitizen());
        for (int i = 0; i < list.size(); i++) {
            EimOuterCitizen c = list.get(i);
            EimDataPerson p = new EimDataPerson();
            p.setName(c.getName());
            p.setPersonId(c.getIdCard());
            p.setPhone(c.getPhone());
            p.setSex(c.getSex());
            p.setAddressCode(c.getNowDistrict());
            p.setAddress(c.getNowAddress());
            p.setIfIn(c.getOuterOther());
            p.setLastGetInTime(c.getInputDate());
            p.setGetInFrom(c.getFromCity());
            p.setAlive(c.getOuterOther());
            p.setIfDiagnosis(c.getIfDiagnosis());
            p.setIfCloseContact(c.getIfCloseContact());
            p.setControlStatus(c.getControlStatus());
            p.setOriginProvince(c.getOriginProvince());
            p.setOriginCity(c.getOriginCity());
            p.setOriginArea(c.getOriginArea());
            p.setOriginAddress(c.getOriginAddress());
            personMapper.insertEimDataPerson(p);
        }
    }

    @Override
    public List<EimOuterCitizen> listExceptionOuterCitizen() {
        return eimOuterCitizenMapper.listExceptionOuterCitizen();
    }

}
